Ready-to-use scripts
Here are collected some useful scripts. Remember to give credit to the author! The toggle script (By Wacov): if frame 1; setVar("repeat",0); setVar("toggle",0); end; if joybutton("a") 0; setVar("repeat",1); getVar("toggle"); elsif getVar("repeat") 0; getVar("toggle"); elsif getVar("toggle") 0; setVar("repeat",0); getSetVar("toggle",1); else;setVar("repeat",0); getSetVar("toggle",0); end; Versatile, good for many kinds of switches. Change 'joybutton("a")' to any key or button input if your model requires; the output of the script is the variable called "toggle". The oscillator script (By Wacov): From the forum: "Seems I'm making one for everything now. This may seemed over-engineered, but the crucial thing is that this is CONTROLLABLE! I've made it as user-friendly as I can, so to change the cycle rate, just change the local variable 'rate' at the top of the script. To make it controllable, which is, ultimately, the point, you can use joystick, slider, button or key entry to change 'rate'. There's also room for expansion, using your own script to control the rate. The output of the script is a variable called "pos," and if the line breaks are removed, this should work straight from a joint's controller box. Could well be useful in the upcoming SketchyPhysics challenge, so here it is: rate=50; if frame 0; setVar("pos",0.5); setVar("direct",1); end; if getVar("pos")>1.0; setVar("direct",0); elsif getVar("pos")<0.0; setVar("direct",1); end; if getVar("direct") 1; getSetVar("pos",getVar("pos")+(1.0/rate)); else; getSetVar("pos",getVar("pos")-(1.0/rate)); end; "This wasn't hard to write, so I don't really want or expect any credit. Use and spread freely!" jump scripts (By BTM and unknown): From the forum: if key("space") 1 then setVar("timer",frame+3); end; if frame<=getVar("timer") and key("space") 0 then setVar("jump",1); else setVar("jump",0); end; that up there is a jump code. When you let go of the spacebar, jump will be set to 1 for 3 frames. A jump code that did that when space was pressed was a little too long and tricky to write, so I made this one. Having it jump after the key is let go also allows for a "wind up" while it's pressed ;) (by BTM) By modifying BTM’s script, I was able to make a jump script that activates when you press Space. if key("Space") 1 and getVar("reset") 0; setVar("start",1) and setVar("reset",1);else setVar("start",0);end if getVar("start") 1; setVar("timer",frame+3);end if frame<=getVar("timer"); setVar("jump",1);else setVar("jump",0);end But that script alone is not enough; you will need to add one of these to the bottom of the script as well. ;if frame>=getVar("timer")+90; setVar("reset",0);end ;if key("Space") 0; setVar("reset",0);end ;if frame>=getVar("timer")+90 and key("Space") 0; setVar("reset",0);end By adding the top line the script won't allow you to jump for another 90 frames. The second line will not let you jump again unless you let go of the spacebar. The third line is a mixture of the first and second lines, where you have to wait 90 frames and let go of the spacebar for it to jump again. Or you can put if frame>=1; setVar("reset",0);end in the Ontouch box of the ground so it will not jump again until you hit(or somthing else hits) the ground. (by someone else) The Acceleration Script (By Wacov): I decided to make this when I realized my new vehicle didn't feel heavy enough; I wanted it to be fast, but I didn't want instant acceleration and decceleration. This script deals with both problems, and you can adjust the acceleration and braking to your needs by changing the local variables at the top...well, here it is: #Acceleration Script by Wacov accel=0.005 deccel=0.015 if frame 0; then; setVar("speed",0.5); end; if getVar("speed")>joyRY and getVar("speed")>0.5; setVar("speed",getVar("speed")-deccel); elsif getVar("speed")0.5; then; setVar("speed",getVar("speed")+accel); end; if joyRY<0.5; then; setVar("speed",getVar("speed")-accel); end; if joyRY 0.5 and getVar("speed")<0.5; setVar("speed",getVar("speed")+deccel); elsif joyRY 0.5 and getVar("speed")>0.5; setVar("speed",getVar("speed")-deccel); end; It will not accelerate beyond the input, so the overall speed is controllable. To change the control, change all the 'joyRY's to whatever you want. To use, place in any onTick field. For a vehicle's motors, use: 0.5-getVar("speed") In the motor's controller field. Hope this is useful! Have at look at this vehicle to see it at work. Category:How-To-Do Category:Scripts